#pragma once

#include <MyFC/Widget.h>
#include <MyFC/Container.h>
#include <MyFC/Glyph.h>

#include "Types.h"
#include "DLL.h"

namespace My {

class Timeline;

/**
 * Navigator widget manages visual navigation
 * in time through a Sequence inside a Timeline.
 */
class DLL_API Navigator : public Widget, public Container
{
	class Control : public My::Control
	{
	protected:
		Navigator &		m_Navigator;
		Timeline &		m_Timeline;
	public:
		Control(Navigator & n);
		virtual bool Visible() const;
	};

	class LeftBracket : public Control
	{
	private:
		int		m_StartPos;
		int		m_StartValue;
		double	m_RightViewBound;
		int		m_MinValue;
		int		m_MaxValue;
	public:
		LeftBracket(Navigator & n) : Control(n) { }
	public:
		virtual CRect Bounds() const;
		virtual String Hint() const; 
		virtual bool HandleDragStart(unsigned int flags, const CPoint & p0, const CPoint & p);
		virtual void HandleDragging(unsigned int flags, const CPoint & p);
	};

	class RightBracket : public Control
	{
	private:
		int		m_StartPos;
		int		m_StartValue;
		double	m_LeftViewBound;
		int		m_MinValue;
		int		m_MaxValue;
	public:
		RightBracket(Navigator & n) : Control(n) { }
	public:
		virtual CRect Bounds() const;
		virtual String Hint() const; 
		virtual bool HandleDragStart(unsigned int flags, const CPoint & p0, const CPoint & p);
		virtual void HandleDragging(unsigned int flags, const CPoint & p);
	};

	class Bar : public Control
	{
	private:
		int	m_StartPos;
		int	m_StartValue;
	public:
		Bar(Navigator & n) : Control(n) { }
	public:
		virtual CRect Bounds() const;
		virtual String Hint() const; 
		virtual bool HandleDragStart(unsigned int flags, const CPoint & p0, const CPoint & p);
		virtual void HandleDragging(unsigned int flags, const CPoint & p);
	};

	class Thumb : public Control
	{
	private:
		int	m_StartPos;
		int	m_StartValue;
	public:
		Thumb(Navigator & n) : Control(n) { }
	public:
		virtual CRect Bounds() const;
		virtual String Hint() const; 
		virtual bool HandleDragStart(unsigned int flags, const CPoint & p0, const CPoint & p);
		virtual void HandleDragEnd(unsigned int flags, const CPoint & p);
		virtual void HandleDragging(unsigned int flags, const CPoint & p);
	};
public:
	Navigator(Timeline & t);
public:
	virtual String Hint() const;
public:
	virtual void ProcessEvent(Event &);
	virtual void HandlePaint(CDC * pDC, const CRect & r);
private:
	int TimeToX(double);
	double XToTime(int);
private:
	Timeline &			m_Timeline;
	LeftBracket			m_LeftBracket;
	RightBracket		m_RightBracket;
	Bar					m_Bar;
	Thumb				m_Thumb;
	My::SysColorGlyph	m_NavThumb;
	My::SysColorGlyph	m_NavWALeft;
	My::SysColorGlyph	m_NavWARight;
	My::SysColorGlyph	m_NavVisibleLeft;
	My::SysColorGlyph	m_NavVisibleRight;
};

} // My